/*
   Copyright (C) 2003, 2005-2008 MySQL AB, 2010 Sun Microsystems, Inc.
    All rights reserved. Use is subject to license terms.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
*/

#ifndef ALTER_TAB_HPP
#define ALTER_TAB_HPP

#include "SignalData.hpp"
#include "GlobalSignalNumbers.h"

struct AlterTabReq {
  STATIC_CONST( SignalLength = 12 );

  enum RequestType {
    AlterTablePrepare = 0, // Prepare alter table
    AlterTableCommit = 1,  // Commit alter table
    AlterTableRevert = 2,  // Prepare failed, revert instead
    AlterTableComplete = 3,
    AlterTableWaitScan = 4,
    AlterTableSumaEnable = 5,
    AlterTableSumaFilter = 6
    ,AlterTableReadOnly = 7  // From TUP to LQH before mtoib
    ,AlterTableReadWrite = 8 // From TUP to LQH after mtoib
  };

  Uint32 senderRef;
  Uint32 senderData;
  Uint32 requestType;
  Uint32 tableId;
  Uint32 tableVersion;
  Uint32 newTableVersion;
  Uint32 gci;
  Uint32 changeMask;

  /* Only used when sending to TUP. */
  Uint32 connectPtr;
  Uint32 noOfNewAttr;
  Uint32 newNoOfCharsets;
  union {
    Uint32 newNoOfKeyAttrs;
    Uint32 new_map_ptr_i;
  };

  SECTION( DICT_TAB_INFO = 0 );
  SECTION( FRAGMENTATION = 1 );
  /*
    When sent to DICT, the first section contains the new table definition.
    When sent to TUP, the first section contains the new attributes.
  */
};

struct AlterTabConf {
  STATIC_CONST( SignalLength = 3 );

  Uint32 senderRef;
  Uint32 senderData;

  /* Only used when sent from TUP. */
  Uint32 connectPtr;
};

struct AlterTabRef {
  STATIC_CONST( SignalLength = 7 );

  Uint32 senderRef;
  Uint32 senderData;
  Uint32 errorCode;
  Uint32 errorLine; 
  Uint32 errorKey;
  Uint32 errorStatus;
  Uint32 connectPtr;
};

/*
  This union can be used to safely refer to a signal data part
  simultaneously as AlterTab{Req,Ref,Conf} without violating the
  strict aliasing rule.
*/
union AlterTabAll {
  AlterTabReq req;
  AlterTabRef ref;
  AlterTabConf conf;
};

#endif
